#!/usr/bin/env python
# Author: Derek Green

PKG = 'pocketsphinx'

import roslib; roslib.load_manifest(PKG)
import rospy

from std_msgs.msg import String
from festival.srv import *

class Reply():
    def __init__(self):
        rospy.Subscriber("/speech_text", String, self.callback)
        rospy.wait_for_service('speak_text')
        try:
            self.speak_text = rospy.ServiceProxy('speak_text', FestivalSpeech)
        except rospy.ServiceException, e:
            print "Failed to acquire Festival SpeakText service: %s"%e
        rospy.init_node('reply_node', anonymous=True)
        rospy.spin()

    def callback(self,data):
        try:
            self.speak_text("Did you say " + str(data.data))
        except rospy.ServiceException, e:
            print "Reply failed: %s"%e

if __name__ == '__main__':
    try:
        r = Reply()
    except rospy.ROSInterruptException: pass

